//
//  CWButton.m
//  CWDevelop
//
//  Created by LittoCats on 7/20/14.
//  Copyright (c) 2014 Littocats. All rights reserved.
//

#import "CWButton.h"
#import "CWBaseView.h"
#import "CWBaseLayout.h"

#import <objc/runtime.h>
#import <objc/message.h>

@implementation CWButton

+ (id)alloc
{
    UIButton *actualButton = [UIButton buttonWithType:UIButtonTypeSystem];
    object_setClass(actualButton, [CWButton class]);
    return (CWButton *)actualButton;
}

- (CGSize)sizeThatFits:(CGSize)size
{
    CGSize newSize = [super sizeThatFits:size];
    if (![self.attributes[@"width"] isEqual:@"wrap_content"])
        newSize.width = self.width;
    if (![self.attributes[@"height"] isEqual:@"wrap_content"])
        newSize.height = self.height;
    
    return newSize;
}

#pragma mark- override default init method
- (void)setText:(NSString *)text
{
    [self setTitle:text forState:UIControlStateNormal];
}
- (NSString *)text
{
    return [self titleForState:UIControlStateNormal];
}

- (void)setTextColor:(UIColor *)color
{
    [self setTitleColor:color forState:UIControlStateNormal];
}
@end
